package com.gmail.shazi199.satoriex.utils;

import org.lwjgl.opengl.GL11;
import org.newdawn.slick.opengl.Texture;

import com.gmail.shazi199.satoriex.stage.image.Picture;

public class Drawer {
    private Drawer() {
    }
    
    public static void draw(Texture texture, int posX, int posY, int width, int height, int picX, int picY) {
        texture.bind();

        float picU = (float) picX / texture.getTextureWidth();
        float picV = (float) picY / texture.getTextureHeight();
        float widthU = (float) width / texture.getTextureWidth();
        float heightV = (float) height / texture.getTextureHeight();

        GL11.glBegin(GL11.GL_QUADS);
            GL11.glTexCoord2f(picU, picV);
            GL11.glVertex2f(posX, posY);
            GL11.glTexCoord2f(picU + widthU, picV);
            GL11.glVertex2f(posX + width, posY);
            GL11.glTexCoord2f(picU + widthU, picV + heightV);
            GL11.glVertex2f(posX + width, posY + height);
            GL11.glTexCoord2f(picU, picV + heightV);
            GL11.glVertex2f(posX, posY + height);
        GL11.glEnd();
    }

    public static void draw(Texture texture, Picture picture) {
        draw(texture, picture.getPosX(), picture.getPosY(), picture.getWidth(), picture.getHeight(), picture.getPicX(), picture.getPicY());
    }

    public static void clear() {
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
    }
}
